/**
 * Created by zhaoxk on 2017/2/22.
 */
import React from 'react';
import moment from 'moment';
import { Icon } from 'antd-mobile';
import ListCustom from '../../../components/list-custom/';
import { carryFN } from '../../../utils';
import styles from './index.less';

moment.locale('zh-cn');
function PatientsList({ gotoDetail, data }) {
    const male = require('../../../assets/img/male.svg');
    const female = require('../../../assets/img/female.svg');
    const clickHandler = (value) => (e) => {
        e.preventDefault();
        carryFN(gotoDetail, value);
    };
    const props = {
        items: (item) => {
            const day = moment().diff(moment(item.entryDate), 'days');
            const gender = item.gender === '1' ? <Icon type={male}/> : <Icon type={female}/>;
            return (
                <div
                    className={styles.patient}
                    onClick={clickHandler(item)}
                >
                    <div className={styles.bedNumber}>{item.bedNumber}</div>
                    <div className={styles.patientInfo}>
                        <div>
                            <span className={styles.name}>{item.name}</span>
                            <span>{gender}</span>
                            <span className={styles.age}>{item.age}</span>
                        </div>
                        <div>
                            <span className={styles.code}>{item.code}</span>
                            <span>|</span>
                            <span className={styles.reasonName}>{item.reasonName}</span>
                        </div>
                    </div>
                    <div className={styles.date}>
                        <div className={styles.entryDate}>{moment(item.entryDate).format('YYYY-MM-DD')}</div>
                        <div className={styles.from}>{`在院 ${day} 天`}</div>
                    </div>
                </div>
            );
        },
        data,
    };
    return (
        <ListCustom
            {...props}
        />
    );
}

export default PatientsList;
